package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhUserAddress;
import com.ruoyi.zsyh.service.IZsyhUserAddressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户地址管理Controller
 * 
 * @author yuexl
 * @date 2022-02-21
 */
@Controller
@RequestMapping("/zsyh/userAddress")
public class ZsyhUserAddressController extends BaseController
{
    private String prefix = "zsyh/userAddress";

    @Autowired
    private IZsyhUserAddressService zsyhUserAddressService;

    @RequiresPermissions("zsyh:userAddress:view")
    @GetMapping()
    public String userAddress()
    {
        return prefix + "/userAddress";
    }

    /**
     * 查询用户地址管理列表
     */
    @RequiresPermissions("zsyh:userAddress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhUserAddress zsyhUserAddress)
    {
        startPage();
        List<ZsyhUserAddress> list = zsyhUserAddressService.selectZsyhUserAddressList(zsyhUserAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址管理列表
     */
    @RequiresPermissions("zsyh:userAddress:export")
    @Log(title = "用户地址管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhUserAddress zsyhUserAddress)
    {
        List<ZsyhUserAddress> list = zsyhUserAddressService.selectZsyhUserAddressList(zsyhUserAddress);
        ExcelUtil<ZsyhUserAddress> util = new ExcelUtil<ZsyhUserAddress>(ZsyhUserAddress.class);
        return util.exportExcel(list, "用户地址管理数据");
    }

    /**
     * 新增用户地址管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户地址管理
     */
    @RequiresPermissions("zsyh:userAddress:add")
    @Log(title = "用户地址管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhUserAddress zsyhUserAddress)
    {
        return toAjax(zsyhUserAddressService.insertZsyhUserAddress(zsyhUserAddress));
    }

    /**
     * 修改用户地址管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhUserAddress zsyhUserAddress = zsyhUserAddressService.selectZsyhUserAddressById(id);
        mmap.put("zsyhUserAddress", zsyhUserAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户地址管理
     */
    @RequiresPermissions("zsyh:userAddress:edit")
    @Log(title = "用户地址管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhUserAddress zsyhUserAddress)
    {
        return toAjax(zsyhUserAddressService.updateZsyhUserAddress(zsyhUserAddress));
    }

    /**
     * 删除用户地址管理
     */
    @RequiresPermissions("zsyh:userAddress:remove")
    @Log(title = "用户地址管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhUserAddressService.deleteZsyhUserAddressByIds(ids));
    }
}
